﻿package mortal.game.view.common.guide.view
{
    import com.gengine.global.*;
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.guide.*;
    import mortal.game.view.task.drama.operations.*;
    import mortal.mvc.core.*;
    import mortal.mvc.events.*;

    public class AutoGuideNewFunc extends View
    {
        protected var _mask:GSprite;
        protected var _needEffect:Boolean = true;
        protected var _bg:GImageBitmap;
        protected var _bmpTitle:GImageBitmap;
        protected var _bmpLabel:GImageBitmap;
        protected var _iconBg:SWFPlayer;
        protected var _icon:BaseItem;
        protected var _arrow:SWFPlayer;
        protected var _bmpClick:GImageBitmap;
        protected var _txtDesc:GTextFiled;
        protected var _swfBg:SWFPlayer;
        protected var _swfYH1:SWFPlayer;
        protected var _swfYH2:SWFPlayer;
        protected var _swfYH3:SWFPlayer;
        protected var _swfYH4:SWFPlayer;
        protected var _timerId:int = -1;
        protected var _callback:Function;
        private static var _hasCloseTaskWin:Boolean = false;
        public static var isShowing:Boolean = false;

        public function AutoGuideNewFunc(param1:Boolean = true)
        {
            this._needEffect = param1;
            this.layer = LayerManager.highestLayer;
            return;
        }// end function

        public function get callback() : Function
        {
            return this._callback;
        }// end function

        public function set callback(param1:Function) : void
        {
            this._callback = param1;
            return;
        }// end function

        public function setLabel(param1:String, param2:String, param3:String) : void
        {
            if (isDisposed)
            {
                return;
            }
            LoaderHelp.setBitmapdata(param1, this._bmpLabel);
            this._icon.source = param2;
            this._txtDesc.htmlText = param3;
            return;
        }// end function

        protected function startTimer() : void
        {
            this._timerId = setTimeout(this.onTimerEnd, 3000);
            return;
        }// end function

        protected function disposeTimer() : void
        {
            if (this._timerId > 0)
            {
                clearTimeout(this._timerId);
                this._timerId = -1;
            }
            return;
        }// end function

        protected function onTimerEnd() : void
        {
            this.clickIconHandler(null);
            return;
        }// end function

        protected function setChangebleUI() : void
        {
            this._bmpTitle = UIFactory.gImageBitmap(null, 193, 38, this);
            LoaderHelp.setBitmapdata("FuncOpen_Func.swf", this._bmpTitle);
            this._bmpClick = UIFactory.gImageBitmap(null, 346, 84, this);
            LoaderHelp.setBitmapdata("FuncOpen_ClickActive.swf", this._bmpClick);
            return;
        }// end function

        override public function stageResize() : void
        {
            super.stageResize();
            DisplayUtil.drawFullScreenMaskByStageXY(this._mask);
            return;
        }// end function

        override public function hide() : void
        {
            isShowing = false;
            super.hide();
            TaskDramaMouseKeyboardControl.enableViews = true;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            this.buttonMode = true;
            this._mask = UICompomentPool.getUICompoment(GSprite) as GSprite;
            this.addChild(this._mask);
            if (this._needEffect)
            {
                this._swfBg = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                this._swfBg.timeRate = 3;
                this._swfBg.move(454, 310);
                this.addChild(this._swfBg);
                this._swfBg.load("FuncOpen_light.swf", ModelType.NormalSwf, null);
            }
            this._bg = UIFactory.gImageBitmap(null, 0, 0, this);
            LoaderHelp.setBitmapdata(ImagesConst.FuncOpenBg + ".swf", this._bg);
            this.setChangebleUI();
            this._bmpLabel = UIFactory.gImageBitmap(null, 44, 88, this);
            this._icon = UIFactory.baseItem(214, 80, 60, 60, this);
            this._iconBg = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
            this._iconBg.timeRate = 1;
            this._iconBg.move(this._icon.x + 230, this._icon.y + 227);
            this.addChild(this._iconBg);
            this._iconBg.load("FuncOpen_Rect.swf", ModelType.NormalSwf, null);
            this._arrow = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
            this._arrow.timeRate = 1;
            this._arrow.move(this._icon.x + 302, this._icon.y + 231);
            this.addChild(this._arrow);
            this._arrow.load("FuncOpen_Arrow.swf", ModelType.NormalSwf, null);
            var _loc_1:* = GlobalStyle.textFormatPutong.center();
            _loc_1.size = 14;
            this._txtDesc = UIFactory.gTextField("", 54, 160, 383, 24, this, _loc_1);
            this.configEventListener(MouseEvent.CLICK, this.clickIconHandler);
            if (this._needEffect)
            {
                this._swfYH1 = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                this._swfYH1.timeRate = 1;
                this._swfYH1.move(161, 312);
                this.addChild(this._swfYH1);
                this._swfYH1.load("FuncOpen_YH1.swf", ModelType.NormalSwf, null);
                this._swfYH2 = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                this._swfYH2.timeRate = 1;
                this._swfYH2.move(297, 138);
                this.addChild(this._swfYH2);
                this._swfYH2.load("FuncOpen_YH1.swf", ModelType.NormalSwf, null);
                this._swfYH3 = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                this._swfYH3.timeRate = 1;
                this._swfYH3.move(606, 138);
                this.addChild(this._swfYH3);
                this._swfYH3.load("FuncOpen_YH1.swf", ModelType.NormalSwf, null);
                this._swfYH4 = UICompomentPool.getUICompoment(SWFPlayer) as SWFPlayer;
                this._swfYH4.timeRate = 1;
                this._swfYH4.move(763, 312);
                this.addChild(this._swfYH4);
                this._swfYH4.load("FuncOpen_YH1.swf", ModelType.NormalSwf, null);
            }
            return;
        }// end function

        override public function get width() : Number
        {
            return 517;
        }// end function

        override public function get height() : Number
        {
            return 190;
        }// end function

        protected function clickIconHandler(event:MouseEvent) : void
        {
            var _loc_2:* = this.mouseX;
            var _loc_3:* = this.mouseY;
            if (event == null || _loc_2 >= 0 && _loc_3 >= 0 && _loc_2 <= 517 && _loc_3 <= 190)
            {
                if (this._callback != null)
                {
                    this._callback.apply();
                    this._callback = null;
                }
                this.hide();
                if (hasCloseTaskWin && GuideController.shouldResumeToTaskAfterGuide())
                {
                    hasCloseTaskWin = false;
                    GameController.guide.resumeToTask();
                }
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            isShowing = true;
            if (_layer)
            {
                _isHide = false;
                _layer.addPopUp(this);
                _layer.centerPopup(this);
                dispatchEvent(new ViewEvent(ViewEvent.Show));
                if (param1 != 0 || param2 != 0)
                {
                    _layer.setPosition(this, param1, param2);
                }
                else
                {
                    _layer.setPosition(this, Global.stage.stageWidth / 2 - 258, Global.stage.stageHeight / 2 - 200);
                }
            }
            this.disposeTimer();
            this.startTimer();
            TaskDramaMouseKeyboardControl.enableViews = false;
            DisplayUtil.drawFullScreenMaskByStageXY(this._mask);
            if (!GameController.npc.isTaskDialogHide())
            {
                hasCloseTaskWin = true;
                GameController.npc.npcDialog.hide();
            }
            return;
        }// end function

        public function setLabelPos(param1:int, param2:int) : void
        {
            this._bmpLabel.x = param1;
            this._bmpLabel.y = param2;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._mask.dispose(param1);
            this._mask = null;
            this._bg.dispose(param1);
            this._bg = null;
            this._bmpTitle.dispose(param1);
            this._bmpTitle = null;
            this._bmpLabel.dispose(param1);
            this._bmpLabel = null;
            this._iconBg.dispose(param1);
            this._iconBg = null;
            this._icon.dispose(param1);
            this._icon = null;
            this._arrow.dispose(param1);
            this._arrow = null;
            this._bmpClick.dispose(param1);
            this._bmpClick = null;
            this._txtDesc.dispose(param1);
            this._txtDesc = null;
            this._callback = null;
            if (this._swfBg != null)
            {
                this._swfBg.dispose(param1);
                this._swfBg = null;
            }
            if (this._swfYH1 != null)
            {
                this._swfYH1.dispose(param1);
                this._swfYH1 = null;
            }
            if (this._swfYH2 != null)
            {
                this._swfYH2.dispose(param1);
                this._swfYH2 = null;
            }
            if (this._swfYH3 != null)
            {
                this._swfYH3.dispose(param1);
                this._swfYH3 = null;
            }
            if (this._swfYH4 != null)
            {
                this._swfYH4.dispose(param1);
                this._swfYH4 = null;
            }
            this.disposeTimer();
            this._needEffect = true;
            return;
        }// end function

        public static function get hasCloseTaskWin() : Boolean
        {
            return _hasCloseTaskWin;
        }// end function

        public static function set hasCloseTaskWin(param1:Boolean) : void
        {
            _hasCloseTaskWin = param1;
            return;
        }// end function

    }
}
